<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<div class="layui-footer" onload="init_foot();">
    <!-- 底部固定区域 -->
    实验室资源申请平台
    create by 计算机软件实验室设计团队 版本v-
    1.0.5
</div>
<script type="text/javascript">
    window.applyCount=null;
</script>
<script type="text/javascript">
    function init_foot(local){
        /*未登录状态下的访问拦截*/
        $.ajax({
            type: "POST",
            url: "${pageContext.request.contextPath}/login.do",
            data: {method: "getRootMsg"},
            dataType: "json",
            success: function (data) {
                if (data != null && data.haveSession == "no") {
                    window.location.href = '../youShouldLogin.jsp';
                } else if (data != null && (data.from == 1) || (data.from == 0)) {
                    window.location.href = '../error.jsp';
                }
            }
        })
        /*显示弹窗*/
        let flag = sessionStorage.getItem("flag");
        if (flag==null || flag==undefined){
            sessionStorage.setItem("flag","yes");
            //调用显示弹窗方法
            showEject();
        }
        if (flag=="yes"){
            showEject();
        }
        if (flag == "no"){
            document.getElementById("redPoint").style.display = "none";
        }
        /*针对不同页面的初始化*/
        if (pageName() == 'personal'){
            $.ajax({
                type:'POST'
                ,url:'${pageContext.request.contextPath}/jsp/root.do?method=getPersonalData'
                ,dataType:'json'
                ,success:function (data) {
                    if (data!=null){
                        $('#rootID').attr("placeholder",data.userCode);
                        $('#rootName').attr("placeholder",data.userName);
                        if (data.rootGrade == "1"){
                            $('#rootMsg').attr("value",data.rootMsg);
                        }else {
                            $('#rootMsg').attr("value","只有一级管理员可以留言");
                            $('#rootMsg').attr("disabled","disabled");
                        }
                    }
                }
            })
        }
    }
    window.onload=init_foot;
    function showEject() {
        if (applyCount == null){
            $.ajax({
                type:"POST"
                ,dataType:"json"
                ,url:"${pageContext.request.contextPath}/jsp/root.do?method=getApplyCount"
                ,success:function (data) {
                    applyCount=data.applyCount;
                    if (applyCount>0){
                        $('#redPoint').attr("class",'layui-badge');
                        /*红点显示*/
                        document.getElementById('redPoint').innerText=applyCount;
                        show();
                    }
                }
                ,error:function () {
                    applyCount=0;
                }
            })
        }else if (applyCount > 0){
            show();
        }
    }
    /*查询未审批数*/
    function show() {
        //弹窗
        layer.open({
            type: 1
            ,title:"<i class='layui-icon' style='color: #ff0000'>&#xe617;</i>审批提示"
            ,offset: ['61.8%','80.8%']
            ,content: '<div style="padding:30px 30px ">您有 <span style="color: red">'+applyCount+'</span> 条审批请求需要审核</br>请进入“申请审批”模块，进行审批</div>'
            ,btn:'进入审批'
            ,btnAlign: 'c' //按钮居中
            ,shade: 0 //不显示遮罩
            ,yes:function () {
                var str='<%=path%>/jsp/root/approval.jsp';
                window.location.href="<%=path%>/jsp/root/approval.jsp";
            }
            ,cancel: function () {
                sessionStorage.setItem("flag","no");
            }
        });
    }
    /*获取当前界面的名称*/
    function pageName() {
        var a = location.href;
        var b = a.split("/");
        var c = b.slice(b.length-1, b.length).toString(String).split(".");
        return c.slice(0, 1);
    }
</script>
</body>
</html>